<template>
    <div class="insurance">
        <div class="card-list">
            <div class="date-box">
                <div class="time-text">时间</div>
                <div class="line">
                    <div class="border-line" v-if="!timeField1">
                        <van-field readonly clickable :value="`请选择`" @click="timePopupShow1 = true"
                                   right-icon="clock-o"/>
                    </div>
                    <div class="border-line" v-if="timeField1">
                        <van-field readonly clickable :value="$formatDateTime(timeVal1, 'yyyy-MM-dd')"
                                   @click="timePopupShow1 = true" right-icon="clock-o"/>
                    </div>
                    <div class="border-line" v-if="!timeField2">
                        <van-field readonly clickable :value="`请选择`" @click="timePopupShow2 = true"
                                   right-icon="clock-o"/>
                    </div>
                    <div class="border-line" v-if="timeField2">
                        <van-field readonly clickable :value="$formatDateTime(timeVal2, 'yyyy-MM-dd')"
                                   @click="timePopupShow2 = true" right-icon="clock-o"/>
                    </div>
                </div>
            </div>
            <van-popup v-model="timePopupShow1" position="bottom">
                <van-datetime-picker v-model="timeVal1" type="date"  @cancel="timePopupShow1 = false"
                                     @confirm="timeConfirm1"/>
            </van-popup>
            <van-popup v-model="timePopupShow2" position="bottom">
                <van-datetime-picker v-model="timeVal2" type="date"  @cancel="timePopupShow2 = false"
                                     @confirm="timeConfirm2"/>
            </van-popup>
            <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
                <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                    <!-- <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> -->
                    <div v-for="(item,index) in listSource" :key="index" :title="item" class="card">
                        <div class="card-top" :style="{backgroundImage: 'url(' + imgUrl1 + ')' }">
                            <div class="card-title">
                                <div>{{item.company_name}}</div>
                                <div class="">{{item.goods_name}}</div>
                            </div>
                            <div class="single-line">地址：{{item.company_address}}</div>
                            <div class="single-line">联系电话：{{item.company_mobile}}</div>
                            <div class="single-line"v-if="item.order_status==10">产品状态：未完成</div>
                            <div class="single-line"v-if="item.order_status==20">产品状态：待审核</div>
                            <div class="single-line"v-if="item.order_status==30">产品状态：待支付</div>
                            <div class="single-line"v-if="item.order_status==40">产品状态：已支付</div>
                            <div class="single-line"v-if="item.order_status==50">产品状态：已过期</div>
                            <div class="single-line"v-if="item.order_status==60">产品状态：已完成</div>
<!--                            <div class="single-line">合同时间：{{item.start_time_text}} ~ {{item.over_time_text}}</div>-->
                            <div class="single-line">产品价格：{{item.price}}</div>
                        </div>
                        <div class="card-btn" :style="{backgroundImage: 'url(' + imgUrl2 + ')' }">
                            <div @click="showPop(item.id,item.order_status)"
                                 :class="item.order_status == 60 ?'gray-color':''">
                                服务完成
                            </div>
                        </div>
                    </div>
                    <div class="pop-window" v-if="isPop">
                        <div class="pop-box">
                            <img src="../../../assets/icon/del_btn.png" alt="">
                            <div class="tishi-text">确认服务已完成？</div>
                            <div class="confirm-btn" @click="confirmInvoice()">确定</div>
                            <img src="../../../assets/icon/close_btn.png" alt="" @click="isPop=false">
                        </div>
                    </div>
                </van-list>
            </van-pull-refresh>
        </div>

    </div>
</template>

<script>
    export default {
        name: "kfConsulting",
        data() {
            return {
                timeField1: false,
                timeVal1: new Date(),
                timePopupShow1: false,

                timeField2: false,
                timeVal2: new Date(),
                timePopupShow2: false,

                minDate: new Date(),
                maxDate: new Date(),

                listSource: [],
                page: 1,
                limit: 10,
                isLoading: false,


                imgUrl1: require('../../../assets/img/card_bg1.png'),
                imgUrl2: require('../../../assets/img/card_bg2.png'),
                list: [],
                loading: false,
                finished: false,

                isPop: false,
                confirmId: '',
            }
        },
        methods: {
            onRefresh() {
                this.page = 1;
                this.onLoad("refresh");
            },
            onLoad(type) {
                let params = {
                    limit: this.limit,
                    page: this.page,
                    wx_member_id: localStorage.getItem('wx_member_id'),
                    token: localStorage.getItem('token'),
                    cate_id: 5,//资讯类

                };
                if (this.timeField1 && this.timeField2) {
                    params.start_time = this.$formatDateTime(this.timeVal1, 'yyyy-MM-dd')
                    params.end_time = this.$formatDateTime(this.timeVal2, 'yyyy-MM-dd')
                }
                this.$post("/api/customer/index", params)
                    .then(res => {
                        if (res.code == 1) {
                            if (type == "refresh") {
                                this.listSource = res.data.dataList;
                                this.isLoading = false;
                                this.finished = false;
                            } else {
                                this.listSource = this.listSource.concat(
                                    res.data.dataList
                                );
                            }
                            this.loading = false;
                            this.page++;
                            if (res.data.dataList.length < this.limit) {
                                this.finished = true;
                            }
                        }
                        if (res.data.count == 0) {
                            this.listSource = ''
                        }
                    })
                    .catch(err => {
                    });
            },

            timeConfirm1() {
                this.timeField1 = true;
                this.timePopupShow1 = false;
                if (this.timeField1 && this.timeField2) {
                    this.onRefresh();
                }

            },
            timeConfirm2() {
                this.timeField2 = true;
                this.timePopupShow2 = false;
                if (this.timeField1 && this.timeField2) {
                    this.onRefresh();
                }
            },
            showPop(id, status) {
                if (status != 60) {
                    this.isPop = true
                    this.confirmId = id
                }
            },
            confirmInvoice() {
                this.isPop = false
                let params = {
                    token: localStorage.getItem('token'),
                    wx_member_id: localStorage.getItem('wx_member_id'),
                    member_goods_id: this.confirmId,
                }
                this.$post("/api/Customer/tax_complete", params)
                    .then(res => {
                        if (res.code == 1) {
                            this.onRefresh()
                        }
                    })
            }
        }
    }
</script>

<style scoped lang="less">
    .card-list {
        padding: 11px;

        .card {
            position: relative;
            color: #fff;
            margin-bottom: 15px;

            .card-top {
                background-size: 100% 100%;
                background-repeat: no-repeat;
                padding: 20px 10px 14px 44px;
                border-radius: 8px 8px 0 0;

                .card-title {
                    display: flex;
                    justify-content: space-between;
                    margin-bottom: 13px;

                    > div {
                        flex: 1;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }

                    > div:nth-of-type(1) {
                        font-size: 16px;
                        font-weight: bold;
                        flex: 1;
                        padding-right: 10px;
                    }

                    > div:nth-of-type(2) {
                        text-align: right;
                        font-size: 12px;
                        padding-left: 10px;
                    }
                }

                .single-line {
                    margin-bottom: 0;
                    font-size: 13px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }

                .single-line:not(:last-child) {
                    margin: 8px 0;
                }

            }

            .card-top-mtext {
                display: flex;
                flex-wrap: wrap;
                background-size: 100% 100%;
                background-repeat: no-repeat;
                padding: 20px 30px;

                .card-title {
                    display: flex;
                    justify-content: space-between;
                    width: 100%;
                    margin-bottom: 13px;

                    > div {
                        font-size: 16px;
                        font-weight: bold;
                    }

                }

                .mtext-line {
                    width: 50%;
                    font-size: 13px;
                    flex-wrap: wrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }

                > .mtext-line:not(:last-child) {
                    margin-bottom: 10px;
                }

                /*> div {*/
                /*    width: 48%;*/
                /*    display: flex;*/
                /*    flex-wrap: wrap;*/
                /*    font-size: 13px;*/
                /*}*/

            }

            .card-btn {
                display: flex;
                justify-content: center;
                align-items: center;
                width: 100%;
                height: 60px;
                /*position: absolute;*/
                bottom: 8px;
                background-size: 100% 100%;
                background-repeat: no-repeat;
                padding: 0 27px;
                box-sizing: border-box;

                div {
                    height: 35px;
                    /*width: 135px;*/
                    margin: 0 8px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    background: #fff;
                    opacity: 0.8;
                    color: #366cb3;
                    border-radius: 5px;
                    font-size: 14px;
                    flex: 1;
                }

                .gray-color {
                    background-color: #c8c8c8;
                    color: #fff;
                }
            }
        }
    }

    .pop-window {
        background: rgba(0, 0, 0, 0.6);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        width: 100vw;
        z-index: 100;

        .pop-box {
            width: 80vw;
            height: 233px;
            margin-left: 10vw;
            background: #fff;
            border-radius: 5px;
            margin-top: 50%;
            display: flex;
            align-items: center;
            flex-direction: column;
            padding-top: 45px;
            position: relative;

            > img:nth-of-type(1) {
                width: 69px;
                height: 69px;
            }

            > img:nth-of-type(2) {
                width: 30px;
                height: 30px;
                position: absolute;
                bottom: -45px;
            }

            .tishi-text {
                font-size: 17px;
                color: #333333;
                padding: 20px 0;
            }

            .confirm-btn {
                width: 150px;
                height: 45px;
                background-image: linear-gradient(-83deg, #e61a1a 0%, #f33e3e 100%),
                linear-gradient(#ff6766, #ff6766);
                background-blend-mode: normal, normal;
                border-radius: 22px;
                display: flex;
                align-items: center;
                justify-content: center;
                color: #fefefe;
                font-size: 16px;
            }
        }
    }


    .date-box {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        margin-bottom: 11px;

        > div:nth-of-type(1) {
            width: 70px;
        }

        .line {
            display: flex;
            align-items: center;

            .border-line {
                padding: 0 2px;
                margin: 0 3px;
                border-radius: 3px;
            }

            .time-text {
                flex-wrap: nowrap;
                width: 50px;
                font-size: 15px;
                color: #333333;
            }
        }
    }
</style>